ScCompiler

Abstract SPIR-V cross compiler Analyses and provides introspection into SPIR-V byte code

abstract
class ScCompiler {}

Destructor

~this
~this()
Undocumented in source.

Members

Functions

bufferGetHlslCounterBuffer
bool bufferGetHlslCounterBuffer(uint id, uint counterId)

Queries if a buffer object has a neighbor "counter" buffer. If so, the ID of that counter buffer will be returned in counter_id. If SPV_GOOGLE_hlsl_functionality1 is used, this can be used even with a stripped SPIR-V module. Otherwise, this query is purely based on OpName identifiers as found in the SPIR-V module, and will only return true if OpSource was reported HLSL. To rely on this functionality, ensure that the SPIR-V module is not stripped.

bufferIsHlslCounterBuffer
bool bufferIsHlslCounterBuffer(uint id)

HLSL counter buffer reflection interface. Append/Consume/Increment/Decrement in HLSL is implemented as two "neighbor" buffer objects where one buffer implements the storage, and a single buffer containing just a lone "int" implements the counter. To SPIR-V these will be exposed as two separate buffers, but glslang HLSL frontend emits a special indentifier which lets us link the two buffers together.

buildCombinedImageSamplers
void buildCombinedImageSamplers()

Analyzes all separate image and samplers used from the currently selected entry point, and re-routes them all to a combined image sampler instead. This is required to "support" separate image samplers in targets which do not natively support this feature, like GLSL/ESSL.

buildDummySamplerForCombinedImages
uint buildDummySamplerForCombinedImages()

Analyzes all OpImageFetch (texelFetch) opcodes and checks if there are instances where said instruction is used without a combined image sampler. GLSL targets do not support the use of texelFetch without a sampler. To workaround this, we must inject a dummy sampler which can be used to form a sampler2D at the call-site of texelFetch as necessary.

compile
string compile()

After parsing, API users can modify the SPIR-V via reflection and call this to disassemble the SPIR-V into the desired langauage. Sub-classes actually implement this.

dispose
void dispose()

Dispose native resources held by the compiler. It is called during GC collection, but can be also called manually.

getActiveBufferRanges
BufferRange[] getActiveBufferRanges(uint id)

Returns a vector of which members of a struct are potentially in use by a SPIR-V shader. The granularity of this analysis is per-member of a struct. This can be used for Buffer (UBO), BufferBlock/StorageBuffer (SSBO) and PushConstant blocks. ID is the Resource::id obtained from get_shader_resources().

getActiveInterfaceVariables
uint[] getActiveInterfaceVariables()

Returns a set of all global variables which are statically accessed by the control flow graph from the current entry point. Only variables which change the interface for a shader are returned, that is, variables with storage class of Input, Output, Uniform, UniformConstant, PushConstant and AtomicCounter storage classes are returned.

getBinaryOffsetForDecoration
bool getBinaryOffsetForDecoration(uint id, spv.Decoration decoration, uint word_offset)

Gets the offset in SPIR-V words (uint) for a decoration which was originally declared in the SPIR-V binary. The offset will point to one or more uint literals which can be modified in-place before using the SPIR-V binary. Note that adding or removing decorations using the reflection API will not change the behavior of this function. If the decoration was declared, sets the word_offset to an offset into the provided SPIR-V binary buffer and returns true, otherwise, returns false. If the decoration does not have any value attached to it (e.g. DecorationRelaxedPrecision), this function will also return false.

getBlockFallbackName
string getBlockFallbackName(uint id)

If get_name() of a Block struct is an empty string, get the fallback name. This needs to be per-variable as multiple variables can use the same block type.

getCleansedEntryPointName
string getCleansedEntryPointName(string name, spv.ExecutionModel executionModel)

New variants of entry point query and reflection. Names for entry points in the SPIR-V module may alias if they belong to different execution models. To disambiguate, we must pass along with the entry point names the execution model.

getCombinedImageSamplers
CombinedImageSampler[] getCombinedImageSamplers()

Gets a remapping for the combined image samplers.

getCurrentIdBound
uint getCurrentIdBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getDeclaredCapabilities
spv.Capability[] getDeclaredCapabilities()

Gets the list of all SPIR-V Capabilities which were declared in the SPIR-V module.

getDeclaredExtensions
string[] getDeclaredExtensions()

Gets the list of all SPIR-V extensions which were declared in the SPIR-V module.

getDeclaredStructMemberSize
size_t getDeclaredStructMemberSize(const(SPIRType)* structType, uint index)

Returns the effective size of a buffer block struct member.

getDeclaredStructSize
size_t getDeclaredStructSize(const(SPIRType)* struct_type)

Returns the effective size of a buffer block.

getDeclaredStructSizeRuntimeArray
size_t getDeclaredStructSizeRuntimeArray(const(SPIRType)* structType, size_t arraySize)

Returns the effective size of a buffer block, with a given array size for a runtime array. SSBOs are typically declared as runtime arrays. getDeclaredStructSize() will return 0 for the size. This is not very helpful for applications which might need to know the array stride of its last member. This can be done through the API, but it is not very intuitive how to accomplish this, so here we provide a helper function to query the size of the buffer, assuming that the last member has a certain size. If the buffer does not contain a runtime array, arraySize is ignored, and the function will behave as getDeclaredStructSize(). To get the array stride of the last member, something like: getDeclaredStructSizeRuntimeArray(type, 1) - getDeclaredStructSizeRuntimeArray(type, 0) will work.

getDecoration
uint getDecoration(uint id, spv.Decoration decoration)
getDecorationString
string getDecorationString(uint id, spv.Decoration decoration)

Gets the value for decorations which take arguments. If the decoration is a boolean (i.e. spv.DecorationNonWritable), 1 will be returned. If decoration doesn't exist or decoration is not recognized, 0 will be returned.

getEntryPointsAndStages
EntryPoint[] getEntryPointsAndStages()

New variants of entry point query and reflection. Names for entry points in the SPIR-V module may alias if they belong to different execution models. To disambiguate, we must pass along with the entry point names the execution model.

getExecutionModeArgument
uint getExecutionModeArgument(spv.ExecutionMode mode, uint index)
getExecutionModel
spv.ExecutionModel getExecutionModel()

Gets argument for an execution mode (LocalSize, Invocations, OutputVertices). For LocalSize, the index argument is used to select the dimension (X = 0, Y = 1, Z = 2). For execution modes which do not have arguments, 0 is returned.

getFallbackMemberName
string getFallbackMemberName(uint index)

Gets the fallback name for a member, similar to getFallbackName.

getFallbackName
string getFallbackName(uint id)

If get_name() is an empty string, get the fallback name which will be used instead in the disassembled source.

getMemberDecoration
uint getMemberDecoration(uint id, uint index, spv.Decoration decoration)
getMemberDecorationString
string getMemberDecorationString(uint id, uint index, spv.Decoration decoration)

Given an OpTypeStruct in ID, obtain the OpMemberDecoration for member number "index".

getMemberName
string getMemberName(uint id, uint index)

Given an OpTypeStruct in ID, obtain the identifier for member number "index". This may be an empty string.

getMemberQualifiedName
string getMemberQualifiedName(uint type_id, uint index)

Returns the qualified member identifier for OpTypeStruct ID, member number "index", or an empty string if no qualified alias exists

getName
string getName(uint id)

Gets the identifier (OpName) of an ID. If not defined, an empty string will be returned.

getNonPointerType
const(SPIRType)* getNonPointerType(uint typeId)

Gets the SPIR-V type underlying the given typeId, which might be a pointer.

getNonPointerTypeId
uint getNonPointerTypeId(uint typeId)

Gets the id of SPIR-V type underlying the given typeId, which might be a pointer.

getRemappedDeclaredBlockName
string getRemappedDeclaredBlockName(uint id)

When declaring buffer blocks in GLSL, the name declared in the GLSL source might not be the same as the name declared in the SPIR-V module due to naming conflicts. In this case, SPIRV-Cross needs to find a fallback-name, and it might only be possible to know this name after compiling to GLSL. This is particularly important for HLSL input and UAVs which tends to reuse the same block type for multiple distinct blocks. For these cases it is not possible to modify the name of the type itself because it might be unique. Instead, you can use this interface to check after compilation which name was actually used if your input SPIR-V tends to have this problem. For other names like remapped names for variables, etc, it's generally enough to query the name of the variables after compiling, block names are an exception to this rule. ID is the name of a variable as returned by Resource::id, and must be a variable with a Block-like type.

getRemappedVariableState
bool getRemappedVariableState(uint id)

Remapped variables are considered built-in variables and a backend will not emit a declaration for this variable. This is mostly useful for making use of builtins which are dependent on extensions.

getShaderResources
ShaderResources getShaderResources()

Query shader resources, use ids with reflection interface to modify or query binding points, etc.

getShaderResources
ShaderResources getShaderResources(const(uint)[] activeVariables)

Query shader resources, but only return the variables which are part of active_variables. E.g.: get_shader_resources(get_active_variables()) to only return the variables which are statically accessed.

getSpecializationConstants
SpecializationConstant[] getSpecializationConstants()

API for querying which specialization constants exist. To modify a specialization constant before compile(), use get_constant(constant.id), then update constants directly in the SPIRConstant data structure. For composite types, the subconstants can be iterated over and modified. constant_type is the SPIRType for the specialization constant, which can be queried to determine which fields in the unions should be poked at.

getStorageClass
spv.StorageClass getStorageClass(uint id)

Gets the underlying storage class for an OpVariable.

getSubpassInputRemappedComponents
uint getSubpassInputRemappedComponents(uint id)

For subpassInput variables which are remapped to plain variables, the number of components in the remapped variable must be specified as the backing type of subpass inputs are opaque.

getType
const(SPIRType)* getType(uint id)

Gets the SPIR-V type associated with ID. Mostly used with Resource::typeId and Resource::baseTypeId to parse the underlying type of a resource.

getTypeFromVariable
const(SPIRType)* getTypeFromVariable(uint id)

Gets the SPIR-V type of a variable.

getWorkGroupSizeSpecializationConstants
uint getWorkGroupSizeSpecializationConstants(SpecializationConstant x, SpecializationConstant y, SpecializationConstant z)

In SPIR-V, the compute work group size can be represented by a constant vector, in which case the LocalSize execution mode is ignored.

hasDecoration
bool hasDecoration(uint id, spv.Decoration decoration)

Returns whether the decoration has been applied to the ID.

hasMemberDecoration
bool hasMemberDecoration(uint id, uint index, spv.Decoration decoration)

Returns whether the decoration has been applied to a member of a struct.

renameEntryPoint
void renameEntryPoint(string old_name, string new_name, spv.ExecutionModel executionModel)

New variants of entry point query and reflection. Names for entry points in the SPIR-V module may alias if they belong to different execution models. To disambiguate, we must pass along with the entry point names the execution model.

setDecoration
void setDecoration(uint id, spv.Decoration decoration, uint argument)
setDecorationString
void setDecorationString(uint id, spv.Decoration decoration, string argument)

Applies a decoration to an ID. Effectively injects OpDecorate.

setEnabledInterfaceVariables
void setEnabledInterfaceVariables(const(uint)[] activeVariables)

Sets the interface variables which are used during compilation. By default, all variables are used. Once set, compile() will only consider the set in active_variables.

setEntryPoint
void setEntryPoint(string entry, spv.ExecutionModel executionModel)

New variants of entry point query and reflection. Names for entry points in the SPIR-V module may alias if they belong to different execution models. To disambiguate, we must pass along with the entry point names the execution model.

setExecutionMode
void setExecutionMode(spv.ExecutionMode mode, uint arg0, uint arg1, uint arg2)
Undocumented in source. Be warned that the author may not have intended to support it.
setMemberDecoration
void setMemberDecoration(uint id, uint index, spv.Decoration decoration, uint argument)

Similar to setDecoration, but for struct members.

setMemberDecorationString
void setMemberDecorationString(uint id, uint index, spv.Decoration decoration, string argument)
Undocumented in source. Be warned that the author may not have intended to support it.
setMemberName
void setMemberName(uint id, uint index, string name)

Sets the member identifier for OpTypeStruct ID, member number "index".

setMemberQualifiedName
void setMemberQualifiedName(uint type_id, uint index, string name)

Sets the qualified member identifier for OpTypeStruct ID, member number "index".

setName
void setName(uint id, string name)

Overrides the identifier OpName of an ID. Identifiers beginning with underscores or identifiers which contain double underscores are reserved by the implementation.

setRemappedVariableState
void setRemappedVariableState(uint id, bool remapEnable)

Remapped variables are considered built-in variables and a backend will not emit a declaration for this variable. This is mostly useful for making use of builtins which are dependent on extensions.

setSubpassInputRemappedComponents
void setSubpassInputRemappedComponents(uint id, uint components)

For subpassInput variables which are remapped to plain variables, the number of components in the remapped variable must be specified as the backing type of subpass inputs are opaque.

typeStructMemberArrayStride
uint typeStructMemberArrayStride(const(SPIRType)* type, uint index)
typeStructMemberMatrixStride
uint typeStructMemberMatrixStride(const(SPIRType)* type, uint index)

API for querying buffer objects. The type passed in here should be the base type of a resource, i.e. getType(resource.baseTypeId) as decorations are set in the basic Block type. The type passed in here must have these decorations set, or an exception is raised. Only UBOs and SSBOs or sub-structs which are part of these buffer types will have these decorations set.

typeStructMemberOffset
uint typeStructMemberOffset(const(SPIRType)* type, uint index)

API for querying buffer objects. The type passed in here should be the base type of a resource, i.e. getType(resource.baseTypeId) as decorations are set in the basic Block type. The type passed in here must have these decorations set, or an exception is raised. Only UBOs and SSBOs or sub-structs which are part of these buffer types will have these decorations set.

unsetDecoration
void unsetDecoration(uint id, spv.Decoration decoration)

Removes the decoration for an ID.

unsetExecutionMode
void unsetExecutionMode(spv.ExecutionMode mode)
Undocumented in source. Be warned that the author may not have intended to support it.
unsetMemberDecoration
void unsetMemberDecoration(uint id, uint index, spv.Decoration decoration)

Unsets a member decoration, similar to unsetDecoration.

Meta